package com.neusoft.a312cxy.android18cxy.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.activity.OrderInfoActivity;
import com.neusoft.a312cxy.android18cxy.bean.ClubCourseBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Young on 2017/10/12.
 */


public class ClubcourseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<ClubCourseBean.ClubcourseBean> mDataList1;
    private LayoutInflater mLayoutInflater;
   // private Button baoming;


    public ClubcourseAdapter(Context mContext, List<ClubCourseBean.ClubcourseBean> mDataList) {
        this.mContext = mContext;
        this.mDataList1 = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }

    @Override
    public  ClubcourseAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.inflate(R.layout.cardview_clubcourse, parent, false);
        return new ViewHolder(v);



    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ClubCourseBean.ClubcourseBean entity =  mDataList1.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.course_name.setText(entity.getCourse_nameX());
        viewHolder.introduction.setText(entity.getIntroductionX());
        viewHolder.end_date.setText(entity.getEnd_dateX());
        viewHolder.start_date.setText(entity.getStart_dateX());
        viewHolder.course_price.setText(entity.getCourse_priceX());

        viewHolder.baoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext,OrderInfoActivity.class);//你要跳转的界面
             //   Intent intent =new Intent(mContext, ClubInfoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("courseid",entity.getIdX());
                bundle.putString("participantname",entity.getCourse_nameX());
                bundle.putString("course_notice",entity.getIntroductionX());
                bundle.putString("course_price",entity.getCourse_priceX());
                intent.putExtras(bundle);
                mContext.startActivity(intent);

            }


        });

        if(!entity.getThumbX().isEmpty())
        {
            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+entity.getThumbX()).into(viewHolder.thumb);
        }
        else
        {
            viewHolder.thumb.setImageResource(R.drawable.ic_club);
        }



    }

    @Override
    public int getItemCount() {
        return mDataList1.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView thumb;
        TextView course_name, introduction,start_date,end_date,course_price;
        Button baoming;





        public ViewHolder(View itemView) {
            super(itemView);
            thumb= (ImageView) itemView.findViewById(R.id.thumb);
            course_name = (TextView) itemView.findViewById(R.id.course_name);
            introduction= (TextView) itemView.findViewById(R.id.introduction);
            start_date=(TextView) itemView.findViewById(R.id.start_date);
            end_date=(TextView) itemView.findViewById(R.id.end_date);
            course_price=(TextView) itemView.findViewById(R.id.course_price);
            baoming=(Button)itemView.findViewById(R.id.baoming);



        }
    }
}
